package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.webservice.weichat.api.MobileMessage;
import com.tianqu.tms.core.webservice.weichat.api.PullingExecutor;
import com.tianqu.tms.core.webservice.weichat.api.rpc.TransferDataSyn30700Bo;
import com.tianqu.tms.dao.CarDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.entity.Member;

public class MarketCarShelveAjaxAction  extends TmsAjaxAction{

	private Logger logger = Logger.getLogger(CarLoadBrandInputAjaxAction.class);
	@Override
	public void process( ActionMapping mapping, ActionForm form
	                                          , HttpServletRequest request
	                                          , HttpServletResponse response
	                                          , UserContext uc)throws TmsException {
		logger.debug(this.getClass().getName() + "#execute.");
		Member menber = Member.getInstance();
		String serial = request.getParameter("serial");
		String shelve = request.getParameter("shelve");
		if(StringUtil.isNullOrBlank(serial)) responseValues(response, "1", TEXT);
		else{
			try {
				CarDao carDao = (CarDao) TmsDao.getInstance(TmsDao.TMS_CAR);
				carDao.updateCarShelve(serial,shelve);
				responseValues(response, "0", TEXT);
				
				//liuyunfei 7、【TMS】库存车辆的上架/下架 =》【车代办】同步
				MobileMessage message = new MobileMessage();
				message.putValue("Serial",serial);
				message.setMessage("【TMS】库存车辆的上架/下架 =》【车代办】同步,Serial为#Serial#");
				
				 TransferDataSyn30700Bo api = new TransferDataSyn30700Bo();
				 api.setMobileMessage(message);
				 api.setIsShelve(Integer.parseInt(shelve));
				 api.setSerial(serial);
				 PullingExecutor.getInstance().submit(api);
			} catch (Exception e) {
				responseValues(response, "1", TEXT);
			}
		}
		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}

}
